package com.example.neusoft215gdh.androidpro_21.Adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.VideoView;

import com.example.neusoft215gdh.androidpro_21.Activity.ClubDetailActivity;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubDetail;
import com.example.neusoft215gdh.androidpro_21.R;

import java.util.List;
/**
 * Created by Rainbow on 2017/9/30.
 */

public class ClubDetailVideoAadapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;//承载上下文
    private List<ClubDetail> mDataList;//动态数组承载数据使用
    private LayoutInflater mLayoutInflater;

    public  ClubDetailVideoAadapter(Context mContext,List<ClubDetail> mDataList){
        this.mContext=mContext;
        this.mDataList=mDataList;
        mLayoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=mLayoutInflater.from(parent.getContext()).inflate(R.layout.card_club_video,parent,false);
        return new  ClubDetailVideoAadapter.ViewHolder(v);
    }

    //将数据绑定到控件
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ClubDetail entity=mDataList.get(position);
        if (null==entity)
            return;
        ClubDetailVideoAadapter.ViewHolder viewHolder= ( ClubDetailVideoAadapter.ViewHolder) holder;

//        if(!entity.getThumb().isEmpty())
//        {
//            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/clubvideo/video/ "+entity.getThumb());
//        }
//        Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/clubvideo/video/ "+ entity.getClubvideo().get(3))


        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, ClubDetailActivity.class);
//                intent.putExtra("food_id",entity.);
//                intent.putExtra("food_name",entity.getFoodname());
//                intent.putExtra("food_price",entity.getPrice());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    //找到控件，将其初始化
    public class ViewHolder extends RecyclerView.ViewHolder{
//       ImageView img;
//        TextView name;
        VideoView videoView;
        public ViewHolder(View itemView) {
            super(itemView);
//            img= (ImageView) itemView.findViewById(R.id.club_pic);
//            name= (TextView) itemView.findViewById(R.id.club_name);
            videoView= (VideoView) itemView.findViewById(R.id.club_video);
        }
    }
}
